package com.huluobo.a2107jetpackkotlindemo.livedata

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.huluobo.a2107jetpackkotlindemo.R

class StudentActivity : AppCompatActivity() {
    lateinit var studentViewModel: StudentViewModel
    lateinit var tvMessage: TextView
    lateinit var edit: EditText
    lateinit var btn: Button

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_student)

        tvMessage = findViewById(R.id.tvMessage)
        studentViewModel = ViewModelProvider(this)[StudentViewModel::class.java]
        edit = findViewById(R.id.student_et)
        btn = findViewById(R.id.student_btn)


//        btn.setOnClickListener {
//            studentViewModel.getScore(edit.text.toString()).observe(this) {
//                tvMessage.text = "分数$it"
//            }
//        }
        btn.setOnClickListener {
            studentViewModel.setStudentId(edit.text.toString())
        }

//        studentViewModel.newScore.observe(this) {
//            tvMessage.text = "分数$it"
//        }

//        studentViewModel.newScore.observe(this, object : Observer<Int> {
//            override fun onChanged(t: Int?) {
//
//            }
//        })
    }
}